package top.ahwyy.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class databaseConnection {
	
	public static final String url= "jdbc:mysql://localhost:3306/blogData2?useUnicode=true&characterEncoding=utf-8";
	public static final String user = "root";
	public static final String password = "123456";
	
	public static Connection conn = null;
	
	public static Connection getADBConnection(){
		//Connection conn = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			if(conn == null)
				conn = DriverManager.getConnection(url,user,password);
			if(conn.isClosed())
				conn = DriverManager.getConnection(url,user,password);
			
			
			System.out.println("connHashCode"+conn.hashCode()+" connStatus"+conn.isClosed()+" conn"+conn.toString());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return conn;
	}
}
